package com.wzh.musichome.cfg;

/**
 * @文件描述
 * @作者 alexhigger
 * @创作日期 2020/11/29 23:43
 */

//
//import com.wzh.musichome.Interceptor.AuthenticationFilter;

import com.wzh.musichome.Interceptor.AuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AuthenticationFilter authenticationFilter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationFilter).
                addPathPatterns("/collect/**")
//                .excludePathPatterns("/consumer/login")
//                .excludePathPatterns("/consumer/add")
//                .excludePathPatterns("/consumer/info")
        ;
    }

    //跨域问题解决
//    @Override
//    public void addCorsMappings(CorsRegistry registry) {
//        registry.
//        addMapping("/**")
//                .allowedOriginPatterns("*")
//                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS","PATCH","TRACE")
//                .allowCredentials(true)
//                .maxAge(3600).allowedHeaders("*");
//    }
//    @Bean
//    public CorsFilter corsFilter() {
//        CorsConfiguration config = new CorsConfiguration();
//        config.addAllowedOrigin("*");
//        config.setAllowCredentials(true);
//        config.addAllowedMethod("*");
//        config.addAllowedHeader("*");
//        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
//        configSource.registerCorsConfiguration("/**", config);
//        return new CorsFilter(configSource);
//    }

}

